import { message, notification, Space } from 'antd'
import { withI18n } from '@lingui/react'
// @withI18n()
// const { location, i18n } = this.props
// import { PATH } from './const/const'
// import { hashHistory } from 'react-router'
//表单布局(居中)
const formItemLayout = {
  labelCol: {
    xs: { span: 24 },
    sm: { span: 2 },
  },
  wrapperCol: {
    xs: { span: 24 },
    sm: { span: 12 },
  },
}

const formItemLayoutPolicy = {
  labelCol: {
    xs: { span: 24 },
    sm: { span: 5 },
  },
  wrapperCol: {
    xs: { span: 24 },
    sm: { span: 18 },
  },
}

const tailLayoutC = {
  wrapperCol: {
    offset: 8,
    span: 16,
  },
}
// 富文本
const tailLayoutF = {
  wrapperCol: {
    offset: 5,
    span: 16,
  },
}
//表单靠左
const formItemLayoutL = {
  labelCol: {
    xs: { span: 24 },
    sm: { span: 3 },
  },
  labelWrap: true,
  wrapperCol: {
    xs: { span: 24 },
    sm: { span: 12 },
  },
}
//表单靠左
const formItemLayoutL6 = {
  labelCol: {
    xs: { span: 24 },
    sm: { span: 6 },
  },
  labelWrap: true,
  wrapperCol: {
    xs: { span: 24 },
    sm: { span: 16 },
  },
}
// 查询
const layout = {
  labelCol: {
    span: 8,
  },
  wrapperCol: {
    span: 16,
  },
}
// 查询
const layoutlist = {
  labelCol: {
    span: 0,
  },
  wrapperCol: {
    span: 24,
  },
}
// Model
const layoutModel = {
  labelCol: {
    span: 6,
  },
  wrapperCol: {
    span: 18,
  },
}
// Modelss
const layoutModelss = {
  labelCol: {
    span: 3,
  },
  wrapperCol: {
    span: 18,
  },
}
const tailLayout = {
  wrapperCol: {
    offset: 18,
    span: 6,
  },
}
// const tailLayout = {
//     wrapperCol: { offset: 8, span: 16 },
//   };
const tailFormItemLayout = {
  wrapperCol: {
    xs: {
      span: 24,
      offset: 0,
    },
    sm: {
      span: 12,
      offset: 6,
    },
  },
}
const formSecurity = {
  labelCol: {
    span: 3,
  },
  wrapperCol: {
    span: 18,
  },
}
//信息条
const success = (title = '修改') => {
  message.success(`${title}`)
}
const error = (title = '修改') => {
  message.error(`${title}成功`)
}
const Deleds = (title = '修改') => {
  message.success(`${title}成功`)
}
const Delede = (title = '修改') => {
  message.error(`${title}成功`)
}
const Modify = (title = '修改') => {
  message.success(`${title}成功`)
}
const Modifys = (title = '修改') => {
  message.error(`${title}成功`)
}
const The = (title = '修改') => {
  message.success(`${title}成功`)
}
const Thes = (title = '修改') => {
  message.error(`${title}成功`)
}
const openNotificationWithIcon = (type, title, value) => {
  notification[type]({
    message: title,
    description: value,
  })
}
const deepClone = (obj) => {
  // 判读obj是否是对象或数组，如果不是的话，直接原样返回
  if (typeof obj !== 'object' || obj == null) {
    return obj
  }
  // 初始化深复制的对象，如果是数组就初始化为数组，是对象就初始化为对象
  let result
  if (obj instanceof Array) {
    result = []
  } else {
    result = {}
  }
  // 遍历原始对象中的属性
  for (let key in obj) {
    // 只复制自己的属性，不复制继承来的属性
    if (obj.hasOwnProperty(key)) {
      // 递归调用，因为原始对象中的属性还有可能是一个对象
      result[key] = this.deepClone(obj[key])
    }
  }
  return result
}
const rTime = (date) => {
  return new Date(date)
    .toISOString()
    .replace(/T/g, ' ')
    .replace(/\.[\d]{3}Z/, '')
}
/**
 * 深拷贝
 * @param {Object} obj 要拷贝的对象
 * @returns
 */
function cloneDeep(obj) {
  // obj 是 null，或者不是对象和数组，直接返回
  if (typeof obj !== 'object' || obj == null) {
    return obj
  }

  // 初始化返回结果
  let result
  if (obj instanceof Array) {
    result = []
  } else {
    result = {}
  }

  for (let key in obj) {
    // 保证 key 不是原型的属性
    if (obj.hasOwnProperty(key)) {
      // 递归调用
      result[key] = cloneDeep(obj[key])
    }
  }

  return result
}
export {
  tailFormItemLayout,
  formItemLayout,
  formItemLayoutPolicy,
  formItemLayoutL,
  formItemLayoutL6,
  tailLayout,
  layout,
  layoutlist,
  layoutModel,
  layoutModelss,
  tailLayoutF,
  success,
  openNotificationWithIcon,
  rTime,
  Deleds,
  Delede,
  Modify,
  Modifys,
  The,
  Thes,
  tailLayoutC,
  formSecurity,
  cloneDeep,
  deepClone,
}
